<template>
  <div class="wl-pagination">
    <el-pagination v-show="total > 0" :layout="layout" :page-sizes="pageSizes" :background="background" :small="small"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="total" :current-page.sync="page"
      :page-size.sync="size">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "wl-pagination",
  props: {
    total: {
      type: Number,
      default: 0
    },
    pageSize: {
      type: Number,
      default: 10
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50];
      }
    },
    currentPage: {
      type: Number,
      default: 1
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper"
    },
    background: {
      type: Boolean,
      default: true
    },
    small: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    // 当前页数
    page: {
      get() {
        return this.currentPage;
      },
      set(val) {
        this.$emit("update:currentPage", val);
      }
    },
    // 当前页数据条数
    size: {
      get() {
        return this.pageSize;
      },
      set(val) {
        this.$emit("update:pageSize", val);
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit("paginationChange");
    },
    handleCurrentChange(val) {
      this.$emit("paginationChange", val);
    }
  }
};
</script>

<style scoped lang="scss">
.wl-pagination {
  display: flex;
  justify-content: flex-end;
  // margin-top: 10px;
}
</style>
